package com.dayu.other.controller;

import java.util.Date;
import java.util.List;

import com.dayu.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dayu.common.annotation.Log;
import com.dayu.common.core.controller.BaseController;
import com.dayu.common.core.domain.AjaxResult;
import com.dayu.common.enums.BusinessType;
import com.dayu.other.domain.DyJudgeObligation;
import com.dayu.other.service.IDyJudgeObligationService;
import com.dayu.common.utils.poi.ExcelUtil;
import com.dayu.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 判责中心Controller
 *
 * @author HK
 * @date 2024-01-24
 */
@RestController
@RequestMapping("/other/obligation")
public class DyJudgeObligationController extends BaseController
{
    @Resource
    private IDyJudgeObligationService dyJudgeObligationService;

    /**
     * 查询判责中心列表
     */
    @PreAuthorize("@ss.hasPermi('other:obligation:list')")
    @GetMapping("/list")
    public TableDataInfo list(DyJudgeObligation dyJudgeObligation)
    {
        startPage();
        List<DyJudgeObligation> list = dyJudgeObligationService.selectDyJudgeObligationList(dyJudgeObligation);
        return getDataTable(list);
    }

    @GetMapping("/price")
    public AjaxResult listPrice(DyJudgeObligation dyJudgeObligation) {
        return AjaxResult.success(dyJudgeObligationService.queryListPrice(dyJudgeObligation));
    }

    /**
     * 导出判责中心列表
     */
    @PreAuthorize("@ss.hasPermi('other:obligation:export')")
    @Log(title = "判责中心", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DyJudgeObligation dyJudgeObligation)
    {
        List<DyJudgeObligation> list = dyJudgeObligationService.selectDyJudgeObligationList(dyJudgeObligation);
        ExcelUtil<DyJudgeObligation> util = new ExcelUtil<DyJudgeObligation>(DyJudgeObligation.class);
        return util.exportExcel(list, "obligation");
    }

    /**
     * 获取判责中心详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dyJudgeObligationService.selectDyJudgeObligationById(id));
    }

    /**
     * 新增判责中心
     */
    @PreAuthorize("@ss.hasPermi('other:obligation:add')")
    @Log(title = "判责中心", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DyJudgeObligation dyJudgeObligation)
    {
        return toAjax(dyJudgeObligationService.insertDyJudgeObligation(dyJudgeObligation));
    }

    /**
     * 修改判责中心
     */
    @Log(title = "判责中心", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DyJudgeObligation dyJudgeObligation)
    {
        return toAjax(dyJudgeObligationService.updateDyJudgeObligation(dyJudgeObligation));
    }

    /**
     * 审核
     */
    @PreAuthorize("@ss.hasPermi('other:obligation:examine')")
    @PutMapping("/examine")
    public AjaxResult examine(@RequestBody DyJudgeObligation dyJudgeObligation){
        dyJudgeObligation.setUpdateTime(new Date());
        dyJudgeObligation.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(dyJudgeObligationService.updateDyJudgeObligation(dyJudgeObligation));
    }

    /**
     * 首页列表
     */
    @GetMapping("/work")
    public AjaxResult work() {
        return AjaxResult.success(dyJudgeObligationService.workQueryList());
    }
}
